package com.zzxz.practicaltrainingsys.controller;

import com.github.pagehelper.PageInfo;
import com.zzxz.practicaltrainingsys.entity.College;
import com.zzxz.practicaltrainingsys.entity.School;
import com.zzxz.practicaltrainingsys.entity.Topic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzxz.practicaltrainingsys.service.TopicService;

import java.util.List;

@Api(tags = "Topic")
@RequestMapping("/topic")
@RestController
@CrossOrigin
public class TopicController {
    @Autowired
    private TopicService topicService;

    @ApiOperation("查找选题信息（分页查询）")
    @GetMapping("/pages")
    public PageInfo<Topic> getPagesTopicList(Integer pageNum, Integer pageSize) {
        return topicService.findTopicPages(pageNum,pageSize);
    }

    //查询所有选题
    @GetMapping("/list")
    public List<Topic> list() {
        return topicService.getTopic();
    }

    //获取所有选题分类
    @GetMapping("/types")
    public List<String> getTopicTypes() {
        return topicService.getTopicTypes();
    }


    //根据项目id查取选题信息（选题名称、简介、应用技术）
    @GetMapping("/listByProject")
    public List<Topic> getTopicsByProjectId(@RequestParam Integer project_id) {
        return topicService.getTopicsByProjectId(project_id);
    }

    //选题表插入
    @PostMapping("/insert")
    public int insertTopic(@RequestBody Topic topic) {

        return topicService.insertTopic(topic);
    }

    @PostMapping("/update")
    public int updateTopic(@RequestBody Topic topic){
        try{
            System.out.println("接收到的更新数据: " + topic); // 打印接收到的数据
            return topicService.updateTopic(topic);}catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    //http://localhost:8080/topic/delete?topic_id=1
    @DeleteMapping("/delete")
    public int deleteTopicById(@RequestParam Integer topic_id){
        return topicService.deleteTopicById(topic_id);
    }
    @GetMapping("/findtopic")
    public List<Topic> getTopicByTopicType(@RequestParam String topic_type){
        return topicService.getTopicByTopicType(topic_type);
    }

    //根据选题id查询选题状态
    @GetMapping("/getTopicState")
    public String getTopicState(@RequestParam Integer topic_id){
        return topicService.getTopicState(topic_id);
    }
    //在新增项目时更新选题状态
    @PostMapping("/updateTopicStateWhenInsertProject")
    public int updateTopicStateWhenInsertProject(@RequestParam Integer topic_id, @RequestParam String topic_state){
        return topicService.updateTopicStateWhenInsertProject(topic_id,topic_state);
    }

    //根据学校编号查询学校
    @GetMapping("/findschool")
    public School getSchoolById(Integer school_id){
        return topicService.getSchoolById(school_id);
    }
    // 根据学院编号查询学院信息
    @GetMapping("/findcollege")
    public College getCollegeById(Integer college_id){
        return topicService.getCollegeById(college_id);
    }





}

